package cn.hfatec.shms.hr.hrLeave.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.hr.hrLeave.model.HrLeave;
import cn.hfatec.shms.hr.hrLeave.dao.HrLeaveDao;
import cn.hfatec.shms.hr.hrLeave.model.HrLeaveParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("HrLeaveService")
public class HrLeaveService {

    public static final String BEAN_ID = "HrLeaveService";

    //注入Dao层
    @Resource(name = "HrLeaveDao")
    private HrLeaveDao hrLeaveDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param hrLeaveParams
     * @param page
     *
     */
    @Transactional
    public Table queryHrLeaveTable(HrLeaveParams hrLeaveParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", hrLeaveParams);
        return baseDao.queryTableByPage("queryHrLeave", params, page);
    }

    /**
     *
     * 插入数据
     * @param hrLeave
     *
     */
    @Transactional
    public void saveHrLeave(HrLeave hrLeave) {
        if(hrLeave.getId() != null) {
            HrLeave result = getHrLeave(hrLeave.getId());
            if(result != null) {
                hrLeaveDao.update(hrLeave);
            } else {
                hrLeaveDao.insert(hrLeave);
            }
        } else {
            hrLeaveDao.insert(hrLeave);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteHrLeave(Integer id) {

        hrLeaveDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param hrLeaveList
     *
     */
    @Transactional
    public void deleteHrLeaveBatch(List<String> hrLeaveList) {
        for(String id : hrLeaveList) {
            deleteHrLeave(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public HrLeave getHrLeave(Integer id) {

        return hrLeaveDao.getHrLeaveById(id);
    }
}